<template>
	<view class="wrap safe-area">
		<view class="wrap-list">
			<block v-for="(item, index) in list" :key="index">
				<view class="item flex align-center just-between" @click="onDetails(item)">
					<view class="title f-28">{{ item.title }}</view>

					<image class="arrow" :src="$staticImagePath('publish/publish_arrow.png')" />
				</view>
			</block>
		</view>
	</view>
</template>

<script>
	import { policyList } from "@/API/mine.js";
	export default {
		data() {
			return {
				page: 1,
				total: 0,
				list: [],
			};
		},
		onLoad() {
			this.onRefresh();
		},
		onPullDownRefresh() {
			this.onRefresh();
		},
		onReachBottom() {
			if (this.list.length < this.total) {
				this.page++;
				this.getData();
			}
		},
		methods: {
			/**
			 * 详情
			 */
			onDetails(item) {
				this.$jump.goHTMLWeb(item.title, "", item.id);
			},
			/**
			 * 刷新
			 */
			onRefresh() {
				this.page = 1;
				this.getData();
			},
			/**
			 * 网络请求
			 */
			getData() {
				policyList(this.page, "policy").then((res) => {
					const list = res.data.data;
					if (this.page === 1) {
						this.total = res.data.total;
						this.list = list;
					} else {
						this.list = this.list.concat(list);
					}
				});
			},
		},
	};
</script>

<style lang="scss" scoped>
	.wrap {
		padding: 20rpx;
		box-sizing: border-box;

		.wrap-list {
			width: 100%;
			overflow: hidden;

			.item {
				width: 100%;
				height: 100rpx;
				border-radius: 16rpx;
				overflow: hidden;
				padding: 0 30rpx;
				box-sizing: border-box;
				gap: 20rpx;
				background-color: white;
				margin-bottom: 20rpx;

				&:last-child {
					margin-bottom: 0rpx;
				}

				.title {
					flex: 1;
					overflow: hidden;
					color: #333333;
				}

				.arrow {
					width: 12rpx;
					height: 20rpx;
				}
			}
		}
	}
</style>
